package view;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import model.DrawableGraph;
import model.DrawableRoute;
import model.Graph;
import model.Route;

/**
 * <p>
 * Title: Map</p>
 * <p>
 * Description: CS 343 Project. Stores the map data model properties.</p>
 *
 * @date 11/18/2013
 *
 * @author Dylan Ahmann
 * @author Gregg Roemhildt - Class programming and Javadocs
 * @author Sam Brockmann - Javadocs
 * @author Emily Hancock - Javadocs
 * @author Shirin Asadi
 *
 *
 */
public class Map extends JPanel {

    private double xOffset, yOffset, zoom;
    private DrawableGraph graph;
    private DrawableRoute route;

    /**
     * default constructor
     *
     * Initializes the graph, xOffset, and yOffset.
     */
    public Map() {
        super();
        graph = null;
        route = null;
        xOffset = 0;
        yOffset = 0;
        zoom = 1;
    }

    /**
     * default constructor
     *
     * Initializes the graph.
     *
     * @param g
     */
    public Map(Graph g) {
        super();
        graph = new DrawableGraph(g);
        route = null;
        xOffset = 0;
        yOffset = 0;
        zoom = 1;
    }

    /**
     * setGraph - sets the graph
     *
     * @param g
     */
    public void setGraph(Graph g) {
        graph = (DrawableGraph) g;
    }

    /**
     * sets a route in the map
     *
     * @param r route to set
     */
    public void setRoute(Route r) {
        route = (DrawableRoute) r;
    }

    /**
     * setOffset Sets the offsets.
     *
     * @param x x offset
     * @param y y offset
     *
     */
    public void setOffset(double x, double y) {
        xOffset = x;
        yOffset = y;
    }

    /**
     * getXOffset - gets the offset of x
     *
     * @return xOffset
     */
    public double getXOffset() {
        return xOffset;
    }

    /**
     * getYOffset - gets the offset of y
     *
     * @return yOffset
     */
    public double getYOffset() {
        return yOffset;
    }

    /**
     * paint
     *
     * @param g defines color pattern
     *
     * Paints the map.
     */
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (graph != null) {
            graph.paint(g, xOffset, yOffset, zoom);
        }

        g.setColor(Color.red);
        if (route != null) {
            route.paint(g, xOffset, yOffset, zoom);
        }
    }

    /**
     * get zoom
     *
     * @return the zoom
     */
    public double getZoom() {
        return zoom;
    }

    /**
     * set zoom
     *
     * @param zoom the zoom to set
     */
    public void setZoom(double zoom) {
        this.zoom = zoom;
    }

}
